#include "Queue.h"
#include "Singleton.h"
#include <iostream>

Queue::Queue( void )
: m_pHead( 0 ), m_pTail( 0 ), m_size( 0 )
{

}

Queue::Queue( DataType value )
{
	Node *pNewNode = new Node;

	pNewNode->value = value;
	pNewNode->pNext = 0;

	m_pHead = m_pTail = pNewNode;
	m_size = 1;
}

void Queue::Enqueue( DataType value )
{
	Node *pNewNode = new Node;

	pNewNode->value = value;
	pNewNode->pNext = 0;

	if ( m_pTail )
	{
		m_pTail->pNext = pNewNode;
		m_pTail = pNewNode;
	}
	else
	{
		m_pHead = m_pTail = pNewNode;
	}

	++m_size;

	cout << Hero::GetInstance()->GetAge() << " ";
	Hero::GetInstance()->SetAge( Hero::GetInstance()->GetAge() + 1 );
}

void Queue::Dequeue( void )
{
	if ( m_pHead == NULL )
		return;

	Node *pTempHead = m_pHead;
	m_pHead = m_pHead->pNext;

	--m_size;

	delete pTempHead;
}

DataType Queue::GetTop( void )
{
	if ( m_pHead )
		return m_pHead->value;

	return 0;
}

Queue::~Queue( void )
{
	while ( m_pHead )
	{
		Node *pTempNode = m_pHead;
		m_pHead = m_pHead->pNext;
		delete pTempNode ;
	}
}